<template>
    {{#if ctrl.psSysPFPlugin}}
    {{> @macro/plugins/widget/widget-use.hbs appPlugin=ctrl.psSysPFPlugin}}
    {{else}}
    <div  :id="controlID" :name="model.codeName" :class="classNames" >
        <div class="control-content">
            <AppEmptyDataTip v-if="store.isNoData || store.errorStatus" :errorStatus="store.errorStatus" :emptyText="emptyText"></AppEmptyDataTip>
                <AppMDCtrl 
                    v-else
                    :items="store.data" 
                    :totalRecord="store.totalRecord"
                    :errorStatus="store.errorStatus"
                    :selections="store.selections"
                    :listMode="listMode"
                    @item-click="handleItemClick"
                    @selection-change="handleSelectionChange"
                    @load-more="handleLoadMore">
                </AppMDCtrl>
        </div>
    </div>

    {{/if}}
</template>
<script setup lang="ts">
{{> @macro/plugins/widget/widget-import.hbs ctrl=ctrl}}
import { Ref } from 'vue';
{{!-- import { AppAnchor } from '@components/common/anchor'; --}}
import { AppMDCtrl } from '@components/widgets/md-ctrl';
import { model } from './{{spinalCase ctrl.codeName}}-list-model';
import { {{pascalCase ctrl.name }}ControlVO } from './{{spinalCase ctrl.codeName}}-list-vo';
import { MDCtrlActionType, MDCtrlController, IContext, IMDCtrlAbility, IMDCtrlControllerParams, IMDCtrlStore, IParam, ICtrlDataAction, IMDCtrlController, createUUID, ILoadingHelper, IViewCtx } from '@/core';
import { useNavParamsBind, useEventBind, getCtrlClassNames } from '@/hooks/use-ctrl';
import MDCtrlService from "@/core/modules/ctrl-service/md-ctrl-service";
{{> @macro/widgets/ctrl/ctrl-props.hbs
    props="openView?: Function;
    newView?: Function;
    actions: ICtrlDataAction;
    singleSelect?: boolean;
    selectFirstDefault?: boolean;
    listMode?: 'default' | 'picker' | 'exp',
    "
    propsDefault="singleSelect: false,listMode:'default',"
}}

{{> @macro/common/emit.hbs name="ctrl" actionType="MDCtrlActionType" ability="IMDCtrlAbility"}}


const controlID = createUUID();

const classNames = computed(() => {
    return getCtrlClassNames(model, props);
});
const emptyText = App.ts(model.emptyTextLanResTag,model.emptyText);
const ctrlService = new MDCtrlService<{{pascalCase ctrl.name}}ControlVO>({{pascalCase ctrl.name}}ControlVO, model.entityCodeName);
//  多数据控制器
const params: IMDCtrlControllerParams<MDCtrlActionType, IMDCtrlAbility> = {
    name: props.name,
    model,
    evt,
    controlID,
    pLoadingHelper: props.pLoadingHelper,
    actions: props.actions,
    openView: props.openView,
    newView: props.newView,
    closeView: props.closeView,
    selectFirstDefault: props.selectFirstDefault,
    singleSelect: props.singleSelect,
    ctrlService: ctrlService,
    handler: (data: IMDCtrlStore) => { return reactive(data) }
};
{{> @macro/common/controller.hbs name="ctrl" IController="IMDCtrlController" store="IMDCtrlStore" ability="IMDCtrlAbility" controller="MDCtrlController"}}

const handleItemClick = (row: IParam, event: MouseEvent) => {
  controller.itemActive(row, event);
}

const handleSelectionChange = (selections: IParam[]) => {
  controller.selectionChange(selections);
}

const handleRefresh = async ()=>{
    return await controller.refresh();
}

const handleLoadMore = async () => {
  await controller.loadMore();
}
</script>